package com.leyikao.controller;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import net.sf.json.JSONObject;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.leyikao.util.HttpRequest;
import com.leyikao.util.ToolUtil;


/**
 * 网站入口首页<br>
 *
 * @author LoadChange
 *
 */
@Controller
@RequestMapping("/")
public class WelcomeCtrl {
	private static final Logger logger = LoggerFactory.getLogger(WelcomeCtrl.class);

	/**
	 * 首页
	 * 
	 * @param request
	 * @return
	 */
	@RequestMapping("/welcome")
	public String index(HttpServletRequest request,Model model) {
		HttpRequest hreq = new HttpRequest();
		//从session获取用户信息
		String enterpriseInfo = request.getSession().getAttribute("enterpriseInfo").toString();
		JSONObject enterpriseObject = JSONObject.fromObject(enterpriseInfo);
		Map<String, Object> enterpriseInfoMap = JSONObject.fromObject(enterpriseObject);
		String ent_uid = enterpriseInfoMap.get("uid").toString();//企业ID
		String params = "\"ent_index_picture_list\"";
		String params1 = "\"ent_job_emergent_view\",\"ent_user_id\":\""+ent_uid+"\"";
		String json = hreq.post(params);
		JSONObject jsonObject = JSONObject.fromObject(json);
    	Map<String, Object> mapJson = JSONObject.fromObject(jsonObject);
    	
    	String json1 = hreq.post(params1);
		JSONObject jsonObject1 = JSONObject.fromObject(json1);
    	Map<String, Object> mapJson1 = JSONObject.fromObject(jsonObject1);
    	
		model.addAttribute("WebSite", "E朝朝_首页")
			 .addAttribute("nav_tag","首页")
			 .addAttribute("pic_list",mapJson.get("data"))
			 .addAttribute("result",mapJson1.get("result"))
			 .addAttribute("emergent",mapJson1.get("data"));
		return "welcome/index";
		
		
	}
	
	/**
	 * 首页-简历搜索
	 * @param request
	 * @param model
	 * @return
	 */
	@RequestMapping("/search")
	public String search(HttpServletRequest request,Model model) {
		HttpRequest hreq = new HttpRequest();
		String pageNO = request.getParameter("pageNo");
		int page = 1;
		if(ToolUtil.strNotNull(pageNO)){
			page = Integer.parseInt(pageNO);
		}
		
		String education_type = "";//学历
		if(ToolUtil.strNotNull(request.getParameter("education")) && !request.getParameter("education").equals("-1")){
			education_type = request.getParameter("education");
		}
		String salary = "";
		if(ToolUtil.strNotNull(request.getParameter("salary")) && !request.getParameter("salary").equals("0")){
			salary = request.getParameter("salary");
		}
		String salary_min = "";
		String salary_max = "";
		if(ToolUtil.strNotNull(salary)){
			if(salary.contains("-")){
				salary_min = salary.substring(0, salary.indexOf('-'));
				salary_max = salary.substring(salary.indexOf("-")+1,salary.length());
			}else if(salary.contains("不限")){
				
			}else{
				salary_min = salary;
				salary_max = salary;
			}
		}
		String major_id = "";
		if(ToolUtil.strNotNull(request.getParameter("child_major")) && !request.getParameter("child_major").equals("0")){
			major_id = request.getParameter("child_major");
		}
		String job_type = "";
		if(ToolUtil.strNotNull(request.getParameter("job_type"))&& !request.getParameter("job_type").equals("-1")){
			job_type = request.getParameter("job_type");
		}
		String city = "";
		if(ToolUtil.strNotNull(request.getParameter("city"))&& !request.getParameter("city").equals("0")){
			city = request.getParameter("city");
		}
		String work_experience = "";
		if(ToolUtil.strNotNull(request.getParameter("work_experience"))&&!request.getParameter("work_experience").equals("0")){
			work_experience = request.getParameter("work_experience");
		}
		
		String params = "\"ent_resume_search_list\",\"page\":\""+page+"\","
				+ "\"certificate_type\":\""+education_type+"\",\"salary_min\":\""+salary_min+"\","
				+ "\"salary_max\":\""+salary_max+"\",\"major_id\":\""+major_id+"\","
				+ "\"employment_type\":\""+job_type+"\",\"city_id_1\":\""+city+"\","
				+ "\"internships\":\""+work_experience+"\"";
		String json = hreq.post(params);
		JSONObject jsonObject = JSONObject.fromObject(json);
    	Map<String, Object> mapJson = JSONObject.fromObject(jsonObject);
    	int result = Integer.parseInt(mapJson.get("result").toString());//本页条数
    	int parent_id=0;
    	String parentID = "";
    	if(ToolUtil.strNotNull(major_id)){
    		parentID = parentList(Integer.parseInt(major_id),"major");
    	}
    	if(ToolUtil.strNotNull(parentID)){
    		parent_id = Integer.parseInt(parentID);
    	}
    	if(result > 0){
    		model.addAttribute("WebSite", "E朝朝_首页_搜索简历")
	    		 .addAttribute("nav_tag","首页")
	    		 .addAttribute("education",education_type)
	    		 .addAttribute("salary",salary)
	    		 .addAttribute("major_id",major_id)
	    		 .addAttribute("parent_id",parent_id)
	    		 .addAttribute("job_type",job_type)
	    		 .addAttribute("city",city)
	    		 .addAttribute("work_experience",work_experience)
				 .addAttribute("resume_list",mapJson.get("data"))
				 .addAttribute("page",page)
				 .addAttribute("result",mapJson.get("result"));
    	}else{
    		model.addAttribute("WebSite", "E朝朝_首页")
    			.addAttribute("nav_tag","首页")
    			.addAttribute("education",education_type)
	    		 .addAttribute("salary",salary)
	    		 .addAttribute("major_id",major_id)
	    		 .addAttribute("parent_id",parent_id)
	    		 .addAttribute("job_type",job_type)
	    		 .addAttribute("city",city)
	    		 .addAttribute("work_experience",work_experience)
    			 .addAttribute("message",mapJson.get("message"))
    			 .addAttribute("page",page)
    		     .addAttribute("result",0);
    	}
		return "welcome/ent_resume";
	}
	
	/**
	 * 首页-急招职位
	 * @param request
	 * @param model
	 * @return
	 */
	@RequestMapping("/emergent")
	public String emergent_job(HttpServletRequest request,Model model) {
		HttpRequest hreq = new HttpRequest();
		//从session获取用户信息
		String enterpriseInfo = request.getSession().getAttribute("enterpriseInfo").toString();
		JSONObject enterpriseObject = JSONObject.fromObject(enterpriseInfo);
		Map<String, Object> enterpriseInfoMap = JSONObject.fromObject(enterpriseObject);
		String ent_uid = enterpriseInfoMap.get("uid").toString();//企业ID
		String params = "\"ent_job_emergent_view\",\"ent_user_id\":\""+ent_uid+"\"";
		String json = hreq.post(params);
		JSONObject jsonObject = JSONObject.fromObject(json);
    	Map<String, Object> mapJson = JSONObject.fromObject(jsonObject);
    	int result = Integer.parseInt(mapJson.get("result").toString());//返回标识
    	if(result > 0){//成功返回
    		model.addAttribute("WebSite", "E朝朝_首页_急招职位")
    		.addAttribute("nav_tag","首页")
			 .addAttribute("emergent_list",mapJson.get("data"));
    	}else{
    		model.addAttribute("WebSite", "E朝朝_首页")
    		.addAttribute("nav_tag","首页")
    		.addAttribute("message",mapJson.get("message"));
    	}
    	return "welcome/ent_emergent";
	}
	
	/**
	 * 
	 * @param request
	 * @param model
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/checkEme")
	public Map<String,Object> checkEmergent(HttpServletRequest request,Model model) {
		Map<String,Object> retur = new HashMap<String,Object>();
		HttpRequest hreq = new HttpRequest();
		//从session获取用户信息
		String enterpriseInfo = request.getSession().getAttribute("enterpriseInfo").toString();
		JSONObject enterpriseObject = JSONObject.fromObject(enterpriseInfo);
		Map<String, Object> enterpriseInfoMap = JSONObject.fromObject(enterpriseObject);
		String ent_uid = enterpriseInfoMap.get("uid").toString();//企业ID
		String params = "\"ent_job_emergent_view\",\"ent_user_id\":\""+ent_uid+"\"";
		String json = hreq.post(params);
		JSONObject jsonObject = JSONObject.fromObject(json);
    	Map<String, Object> mapJson = JSONObject.fromObject(jsonObject);
    	int result = Integer.parseInt(mapJson.get("result").toString());//返回标识
    	String temp = mapJson.get("data").toString();
    	JSONObject tempObject = JSONObject.fromObject(temp.substring(1, temp.length()-1));
    	Map<String, Object> tmpMap = JSONObject.fromObject(tempObject);
    	String id = tmpMap.get("id").toString();
    	if(result > 0 && id!=null && !"".equals(id) && !"null".equals(id)){//成功返回
    		retur.put("success", true);
    	}else{
    		retur.put("success", false);
    	}
    	return retur;
	}
	
	/**
	 * 首页-发布职位
	 * @param request
	 * @param model
	 * @return
	 */
	@RequestMapping("/postoffice")
	public String post_office(HttpServletRequest request,Model model) {
		model.addAttribute("WebSite", "E朝朝_首页_发布职位")
		.addAttribute("nav_tag","首页");
		return "welcome/ent_postoffice";
	}
	
	/**
	 * 首页-我的职位
	 * @param request
	 * @param model
	 * @return
	 */
	@RequestMapping("/ownjob")
	public String own_job(HttpServletRequest request,Model model) {
		model.addAttribute("WebSite", "E朝朝_首页_我的职位")
		.addAttribute("nav_tag","首页");
		return "welcome/ent_job";
	}
	
	/**
	 * 职位详情
	 * @param id
	 * @param request
	 * @param model
	 * @return
	 */
	
	@RequestMapping("/ownjob/j_{id}.html")
	public String jobDetail(@PathVariable("id") String id,HttpServletRequest request,Model model) {
		HttpRequest hreq = new HttpRequest();
		String num = request.getParameter("resume");
		//从session获取用户信息
		String enterpriseInfo = request.getSession().getAttribute("enterpriseInfo").toString();
		JSONObject enterpriseObject = JSONObject.fromObject(enterpriseInfo);
		Map<String, Object> enterpriseInfoMap = JSONObject.fromObject(enterpriseObject);
		String uid = enterpriseInfoMap.get("uid").toString();//企业ID
		String params = "\"ent_job_detail\",\"uid\":\""+uid+"\",\"jid\":\""+id+"\"";
		String json = hreq.post(params);
		JSONObject jsonObject = JSONObject.fromObject(json);
    	Map<String, Object> mapJson = JSONObject.fromObject(jsonObject);
    	int result = Integer.parseInt(mapJson.get("result").toString());//返回标识
    	if(result > 0){//成功返回
    		model.addAttribute("WebSite", "E朝朝_首页_职位详情")
    		.addAttribute("nav_tag","首页")
    		.addAttribute("num", num)
			 .addAttribute("job_list",mapJson.get("data"));
    	}else{
    		model.addAttribute("WebSite", "E朝朝_首页_职位详情")
    		.addAttribute("nav_tag","首页")
    		.addAttribute("message",mapJson.get("message"));
    	}
		return "welcome/ent_job_detail";
	}
	
	/**
	 * 职位收到简历列表
	 * @param request
	 * @param model
	 * @return
	 */
	@RequestMapping("/ownjob/jobresume")
	public String jobReume(HttpServletRequest request,Model model) {
		HttpRequest hreq = new HttpRequest();
		String id = request.getParameter("job");
		//从session获取用户信息
		String enterpriseInfo = request.getSession().getAttribute("enterpriseInfo").toString();
		JSONObject enterpriseObject = JSONObject.fromObject(enterpriseInfo);
		Map<String, Object> enterpriseInfoMap = JSONObject.fromObject(enterpriseObject);
		String uid = enterpriseInfoMap.get("uid").toString();//企业ID
		String params = "\"ent_job_detail\",\"uid\":\""+uid+"\",\"jid\":\""+id+"\"";
		String params1 = "\"ent_job_emergent_view\",\"ent_user_id\":\""+uid+"\"";
		
		String json = hreq.post(params);
		JSONObject jsonObject = JSONObject.fromObject(json);
    	Map<String, Object> mapJson = JSONObject.fromObject(jsonObject);
    	
//    	String json1 = hreq.post(params1);
//		JSONObject jsonObject1 = JSONObject.fromObject(json1);
//    	Map<String, Object> mapJson1 = JSONObject.fromObject(jsonObject1);
//    	String temp=mapJson1.get("data").toString();
//    	//[{"id":null,"title":null,"job_type":null,"work_type":"全职","salary":null,"over_time":"00:00:00","resume_num":"0","resume_max":null}]
//    	String tmpID = "";
//    	int eID=0;
//    	if(ToolUtil.strNotNull(temp)){
//	    	tmpID=temp.substring(8,temp.indexOf(",\"title")-1);
//    	}
//    	if(!"null".equals(tmpID)&& tmpID!=null&&!"".equals(tmpID)){
//    		eID = Integer.parseInt(tmpID);
//    	}
//    	int flag=0;
//    	if(eID==Integer.parseInt(id)){
//    		flag=1;
//    	}
    	
		model.addAttribute("WebSite", "E朝朝_首页_职位收到简历列表")
			.addAttribute("id", id)
//			.addAttribute("emergentFlag", flag)
			.addAttribute("jobresume", mapJson.get("data"))
			.addAttribute("nav_tag","首页");
		return "welcome/ent_job_resume";
	}
	
	/**
	 * 获取急招职位收到的简历列表
	 * @param request
	 * @param model
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/emergent/resume")
	public Map<String,Object> job_resume_lit(HttpServletRequest request,Model model){
		HttpRequest hreq = new HttpRequest();
		String id = request.getParameter("positionID");//职位ID
		int page = 1;//当前页码
		if(ToolUtil.strNotNull(request.getParameter("pageNO"))){
			page = Integer.parseInt(request.getParameter("pageNO"));
		}
		String emergent = request.getParameter("emergent");//是否急招：0否，1是
		String params = "\"ent_job_resume_list\",\"job_id\":\""+id+"\",\"emergent\":\""+emergent+"\",\"page\":\""+page+"\"";
		String json = hreq.post(params);
		JSONObject jsonObject = JSONObject.fromObject(json);
    	Map<String, Object> mapJson = JSONObject.fromObject(jsonObject);
    	String temp = mapJson.get("data").toString();
    	if(temp.indexOf(":null")>0){
    		temp = temp.replace(":null", ":\"\"");
    		mapJson.put("data", temp);
    	}
    	mapJson.put("page", page);
    	model.addAllAttributes(mapJson);
		return mapJson;
	}
	
	/**
	 * 数据字典-专业
	 * @param request
	 * @param model
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/major_list")
	public Map<String,Object> major_list(HttpServletRequest request,Model model) {
		HttpRequest hreq = new HttpRequest();
		int parent_id = 0;
		if(ToolUtil.strNotNull(request.getParameter("id"))){
			parent_id = Integer.parseInt(request.getParameter("id"));
		}
		String params = "\"ent_data_major_list\",\"parent_id\":\""+parent_id+"\"";
		String json = hreq.post(params);
		JSONObject jsonObject = JSONObject.fromObject(json);
    	Map<String, Object> mapJson = JSONObject.fromObject(jsonObject);
    	model.addAllAttributes(mapJson);
		return mapJson;
	}
	
	/**
	 * 数据字典-城市（含省市分类）列表
	 * @param request
	 * @param model
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/city_list")
	public Map<String,Object> city_list(HttpServletRequest request,Model model) {
		HttpRequest hreq = new HttpRequest();
		String parent_id = request.getParameter("parentID");
		if(!ToolUtil.strNotNull(parent_id)){
			parent_id = "0";
		}
		String params = "\"ent_data_city_list\",\"parent_id\":\""+parent_id+"\"";
		String json = hreq.post(params);
		JSONObject jsonObject = JSONObject.fromObject(json);
    	Map<String, Object> mapJson = JSONObject.fromObject(jsonObject);
    	model.addAllAttributes(mapJson);
		return mapJson;
	}
	
	/**
	 * 数据字典-所属行业列表
	 * @param request
	 * @param model
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/industry_list")
	public Map<String,Object> industry_list(HttpServletRequest request,Model model) {
		HttpRequest hreq = new HttpRequest();
		String pid = request.getParameter("parentID");
		if(!ToolUtil.strNotNull(pid)){
			pid = "0";
		}
		String params = "\"ent_data_industry_list\",\"parent_id\":\""+pid+"\"";
		String json = hreq.post(params);
		JSONObject jsonObject = JSONObject.fromObject(json);
    	Map<String, Object> mapJson = JSONObject.fromObject(jsonObject);
    	model.addAllAttributes(mapJson);
		return mapJson;
	}
	
	/**
	 * 数据字典-职位名称
	 * @param request
	 * @param model
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/job_list")
	public Map<String,Object> job_list(HttpServletRequest request,Model model) {
		HttpRequest hreq = new HttpRequest();
		String pid = request.getParameter("parentID");
		if(!ToolUtil.strNotNull(pid)){
			pid = "0";
		}
		String params = "\"ent_data_job_list\",\"parent_id\":\""+pid+"\"";
		String json = hreq.post(params);
		JSONObject jsonObject = JSONObject.fromObject(json);
    	Map<String, Object> mapJson = JSONObject.fromObject(jsonObject);
    	model.addAllAttributes(mapJson);
		return mapJson;
	}
	
	/**
	 * 我的职位
	 * @param request
	 * @param model
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/own_job_list")
	public Map<String,Object> own_job_list(HttpServletRequest request,Model model) {
		HttpRequest hreq = new HttpRequest();
		//从session获取用户信息
		String enterpriseInfo = request.getSession().getAttribute("enterpriseInfo").toString();
		JSONObject enterpriseObject = JSONObject.fromObject(enterpriseInfo);
		Map<String, Object> enterpriseInfoMap = JSONObject.fromObject(enterpriseObject);
		String uid = enterpriseInfoMap.get("uid").toString();//企业ID
		String status = request.getParameter("status");//职位状态：-3 审核未通过 -2 已保存 -1 待审核 0上线 1 下线
		String page = request.getParameter("pageNO");//当前页码
		if(!ToolUtil.strNotNull(status)){
			status = "0";
		}
		if(!ToolUtil.strNotNull(page)){
			page = "1";
		}
		String params = "\"ent_job_list\",\"uid\":\""+uid+"\",\"status\":\""+status+"\",\"page\":\""+page+"\"";
		String json = hreq.post(params);
		JSONObject jsonObject = JSONObject.fromObject(json);
    	Map<String, Object> mapJson = JSONObject.fromObject(jsonObject);
    	model.addAllAttributes(mapJson);
		return mapJson;
	}
	
	/**
	 * 设置急招
	 * @param request
	 * @param model
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/ownjob/set_emergent")
	public Map<String,Object> set_emergent(HttpServletRequest request,Model model) {
		HttpRequest hreq = new HttpRequest();
		Map<String, Object> result = new HashMap<String,Object>();
		//从session获取用户信息
		String enterpriseInfo = request.getSession().getAttribute("enterpriseInfo").toString();
		JSONObject enterpriseObject = JSONObject.fromObject(enterpriseInfo);
		Map<String, Object> enterpriseInfoMap = JSONObject.fromObject(enterpriseObject);
		String ent_user_id = enterpriseInfoMap.get("uid").toString();//企业ID
		String id = request.getParameter("ent_job_id");
		String max_count = request.getParameter("max_count");
		String params = "\"ent_job_emergent_status\",\"ent_user_id\":\""+ent_user_id+"\",\"ent_job_id\":\""+id+"\",\"max_count\":\""+max_count+"\"";
		String json = hreq.post(params);
		JSONObject jsonObject = JSONObject.fromObject(json);
    	Map<String, Object> mapJson = JSONObject.fromObject(jsonObject);
    	int res = Integer.parseInt(mapJson.get("result").toString());//返回标识
    	if(res > 0){//成功返回
    		result.put("success", true);
    	}else{
    		result.put("success", false);
    		result.put("message", mapJson.get("message"));
    	}
		return result;
	}
	
	/**
	 * 修改职位状态
	 * @param request
	 * @param model
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/ownjob/set_status")
	public Map<String,Object> set_status(HttpServletRequest request,Model model) {
		HttpRequest hreq = new HttpRequest();
		Map<String, Object> result = new HashMap<String,Object>();
		String id = request.getParameter("ent_job_id");//职位ID
		String status = request.getParameter("status");//新状态：1 下线 0 上线 -1 待审核 -2 已保存 -3 审核未通过  -8 刷新 -9 删除
		String params = "\"ent_job_status\",\"job_ids\":\""+id+"\",\"new_status\":\""+status+"\"";
		
		//修改职位状态问题暂时用E朝朝接口
		String url = "http://interface.ezz2.1zhaozhao.com/interface_ent/";
		String token = "0a20ece95e098dd38621410f5a3f8dda";
		String name = "post_json";
		String param = name+"={\"token\":\""+token+"\",\"type\":"+params+"}";
		String json =  hreq.sendPost(url, param);
		
//		String json = hreq.post(params);
		JSONObject jsonObject = JSONObject.fromObject(json);
    	Map<String, Object> mapJson = JSONObject.fromObject(jsonObject);
    	int res = Integer.parseInt(mapJson.get("result").toString());//返回标识
    	if(res > 0){//成功返回
    		result.put("success", true);
    	}else{
    		result.put("success", false);
    		result.put("message", mapJson.get("message"));
    	}
		return result;
	}
	
	/**
	 * 保存修改职位
	 * @param request
	 * @param model
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/postoffice/operatorjob")
	public Map<String,Object> operatorJob(HttpServletRequest request,Model model) {
		HttpRequest hreq = new HttpRequest();
		Map<String, Object> result = new HashMap<String,Object>();
		String job_id = request.getParameter("job_id");//职位ID
		String action_type = request.getParameter("action_type");//1=保存，2=提交
		//从session获取用户信息
		String enterpriseInfo = request.getSession().getAttribute("enterpriseInfo").toString();
		JSONObject enterpriseObject = JSONObject.fromObject(enterpriseInfo);
		Map<String, Object> enterpriseInfoMap = JSONObject.fromObject(enterpriseObject);
		String uid = enterpriseInfoMap.get("uid").toString();//企业ID
		String title = request.getParameter("title");
		String parentIndustryID = request.getParameter("parentIndustry_id");
		String industry_id = request.getParameter("industry_id");//二级行业
		String job_type_id = request.getParameter("job_type_id");//职位名称ID
		String need_count = request.getParameter("need_count");//招聘人数
		String certificate_type = request.getParameter("certificate_type");//学历要求
		String work_exp_type = request.getParameter("work_exp_type");//0不限 1有经验 2无经验
		String department = request.getParameter("department");//所属部门
		String work_type = request.getParameter("work_type");//职位类型
		String salary_min = request.getParameter("salary_min");//薪资下线
		String salary_max = request.getParameter("salary_max");//薪资上线
		String benefit = request.getParameter("benefit");//职位福利
		String city_id_1 = request.getParameter("city_id_1");//工作地区-省
		String city_id_2 = request.getParameter("city_id_2");//工作地区-市
		String city_id_3 = request.getParameter("city_id_3");//工作地区-区县
		String address = request.getParameter("address");//工作地点
		String job_description = request.getParameter("job_description");//职位描述
		String latitude = request.getParameter("latitude");//维度
		String longitude = request.getParameter("longitude");//经度
		String publicIndusID="";
		if(ToolUtil.strNotNull(industry_id)){//判断行业ID值:行业二级有值直接传
			publicIndusID = industry_id;
		}else{
			if(ToolUtil.strNotNull(parentIndustryID)){//判断行业ID值:行业一级有值直接传
				publicIndusID = parentIndustryID;
			}
		}
		String params = "\"ent_job_save\",\"job_id\":\""+job_id+"\","
				+ "\"action_type\":\""+action_type+"\",\"uid\":\""+uid+"\","
				+ "\"title\":\""+title+"\",\"industry_id\":\""+publicIndusID+"\","
				+ "\"job_type_id\":\""+job_type_id+"\",\"need_count\":\""+need_count+"\","
				+ "\"certificate_type\":\""+certificate_type+"\",\"work_exp_type\":\""+work_exp_type+"\","
				+ "\"department\":\""+department+"\",\"work_type\":\""+work_type+"\","
				+ "\"salary_min\":\""+salary_min+"\",\"salary_max\":\""+salary_max+"\","
				+ "\"benefit\":\""+benefit+"\",\"city_id_1\":\""+city_id_1+"\","
				+ "\"city_id_2\":\""+city_id_2+"\",\"city_id_3\":\""+city_id_3+"\","
				+ "\"address\":\""+address+"\",\"job_description\":\""+job_description+"\","
				+ "\"latitude\":\""+latitude+"\",\"longitude\":\""+longitude+"\"";
		String json = hreq.post(params);
		JSONObject jsonObject = JSONObject.fromObject(json);
    	Map<String, Object> mapJson = JSONObject.fromObject(jsonObject);
    	int res = Integer.parseInt(mapJson.get("result").toString());//返回标识
    	if(res > 0){//成功返回
    		result.put("success", true);
    	}else{
    		result.put("success", false);
    		result.put("message", mapJson.get("message"));
    	}
		return result;
	}
	
	
	/**
	 * 首页-编辑职位
	 * @param request
	 * @param model
	 * @return
	 */
	@RequestMapping("/updatejob/job{id}.html")
	public String update_job(@PathVariable("id") String id,HttpServletRequest request,Model model) {
		HttpRequest hreq = new HttpRequest();
		String num = request.getParameter("resume");
		//从session获取用户信息
		String enterpriseInfo = request.getSession().getAttribute("enterpriseInfo").toString();
		JSONObject enterpriseObject = JSONObject.fromObject(enterpriseInfo);
		Map<String, Object> enterpriseInfoMap = JSONObject.fromObject(enterpriseObject);
		String uid = enterpriseInfoMap.get("uid").toString();//企业ID
		String params = "\"ent_job_detail\",\"uid\":\""+uid+"\",\"jid\":\""+id+"\"";
		String json = hreq.post(params);
		JSONObject jsonObject = JSONObject.fromObject(json);
    	Map<String, Object> mapJson = JSONObject.fromObject(jsonObject);
    	System.out.println("detail=="+mapJson.get("data"));
    	int result = Integer.parseInt(mapJson.get("result").toString());//返回标识
    	if(result > 0){//成功返回
    		//查询父级所属行业"industry_id2":"33","ent_type
    		String industryString = mapJson.get("data").toString();
    		int industry_a = industryString.indexOf("industry_id");
    		int industry_b = industryString.indexOf("job_type_name");
    		String parent = "";
    		if(ToolUtil.strNotNull(industryString.substring(industry_a+14,industry_b-3))){
    			int industryFlag = Integer.valueOf(industryString.substring(industry_a+14,industry_b-3));
    			parent = parentList(industryFlag,"industry");
    		}
    		
    		String jobString = mapJson.get("data").toString();
    		int job_a = jobString.indexOf("job_type_id");
    		int jon_b = jobString.indexOf("need_count");
    		String job_parent = "";
    		if(ToolUtil.strNotNull(jobString.substring(job_a+14,jon_b-3))){
    			int jobFlag = Integer.valueOf(jobString.substring(job_a+14,jon_b-3));
    			job_parent = parentList(jobFlag,"job_type");
    		}
    		
    		model.addAttribute("WebSite", "E朝朝_首页_编辑职位")
    		.addAttribute("nav_tag","首页")
    		.addAttribute("num", num)
    		.addAttribute("parent",parent)
    		.addAttribute("job_parent",job_parent)
			 .addAttribute("job_list",mapJson.get("data"));
    	}else{
    		model.addAttribute("WebSite", "E朝朝_首页")
    		.addAttribute("nav_tag","首页")
    		.addAttribute("message",mapJson.get("message"));
    	}
		
		return "welcome/ent_updateoffice";
	}
	
	public String parentList(int parent_id,String class_name) {
		//int parent_id=Integer.valueOf(request.getParameter("parent_id"));
		//String class_name = request.getParameter("class_name");//city、industry、job_type、major
		HttpRequest hreq = new HttpRequest();
		String params = "\"ent_get_fid\",\"id\":\""+parent_id+"\",\"class_name\":\""+class_name+"\"";
		String json = hreq.post(params);
		JSONObject jsonObject = JSONObject.fromObject(json);
		System.out.println(jsonObject);
		Map<String, Object> mapJson = JSONObject.fromObject(jsonObject);
		return mapJson.get("data").toString();
	}
}
